package org.pih.javarosa.model;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;

import org.javarosa.core.model.instance.FormInstance;
import org.javarosa.core.model.instance.TreeReference;
import org.javarosa.core.model.util.restorable.Restorable;
import org.javarosa.core.model.util.restorable.RestoreUtils;
import org.javarosa.core.services.storage.Persistable;
import org.javarosa.core.util.externalizable.DeserializationException;
import org.javarosa.core.util.externalizable.ExtUtil;
import org.javarosa.core.util.externalizable.ExtWrapMap;
import org.javarosa.core.util.externalizable.ExtWrapNullable;
import org.javarosa.core.util.externalizable.PrototypeFactory;
import org.javarosa.patient.model.data.ImmunizationData;
import org.javarosa.patient.model.data.NumericListData;

public class Country implements Persistable, Restorable {

	private static final int INVALID_RECORD_ID = -1;

	public static final String STORAGE_KEY = "Country";
	
	/** RMS Record Id */
	private int recordId = INVALID_RECORD_ID;
	
	private String name;
	
	private String protocolXFormPath;
	public void setProtocolXFormPath(String protocolXFormPath) {
		this.protocolXFormPath = protocolXFormPath;
	}
	public String getProtocolXFormPath() {
		return protocolXFormPath;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getName() {
		return name;
	}
	public int getID() {
		return recordId;
	}
	public void setID(int ID) {
		this.recordId = ID;
	}
	public void readExternal(DataInputStream in, PrototypeFactory pf)
			throws IOException, DeserializationException {
		recordId = ExtUtil.readInt(in);
		setName((String)ExtUtil.read(in, new ExtWrapNullable(String.class), pf));
//		setFamilyName((String)ExtUtil.read(in, new ExtWrapNullable(String.class), pf));
//		setMiddleName((String)ExtUtil.read(in, new ExtWrapNullable(String.class), pf));
//		setGivenName((String)ExtUtil.read(in, new ExtWrapNullable(String.class), pf));
//		setGender(ExtUtil.readInt(in));
//		setBirthDate((Date)ExtUtil.read(in, new ExtWrapNullable(Date.class), pf));
//		setTreatmentStartDate((Date)ExtUtil.read(in, new ExtWrapNullable(Date.class), pf));
//		setPatientIdentifier((String)ExtUtil.read(in, new ExtWrapNullable(String.class), pf));
//		setNewPatient(ExtUtil.readBool(in));
//
//		vaccinationData = (ImmunizationData)ExtUtil.read(in, ImmunizationData.class);
//		
//		records = (Hashtable)ExtUtil.read(in, new ExtWrapMap(String.class, NumericListData.class));
//		singles = (Hashtable)ExtUtil.read(in, new ExtWrapMap(String.class, String.class));
	}
	public void writeExternal(DataOutputStream out) throws IOException {
		// TODO Auto-generated method stub
		
	}
	public FormInstance exportData() {
		FormInstance formInstance = RestoreUtils.createDataModel(this);
		RestoreUtils.addData(formInstance, "drug-id", "" + recordId);
		RestoreUtils.addData(formInstance, "name", name);
		return formInstance;
	}
	public String getRestorableType() {
		return "drug";
	}
	public void importData(FormInstance dm) {
		// TODO Auto-generated method stub
		
	}
	public void templateData(FormInstance dm, TreeReference parentRef) {
		// TODO Auto-generated method stub
		
	}
	
}
